package com.qfedu.mall.api.controller;

import com.qfedu.mall.beans.vo.UserAddrVO;
import com.qfedu.mall.common.vo.AdrrId;
import com.qfedu.mall.common.vo.ResultVO;
import com.qfedu.mall.service.UserAddrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Api(value = "提供收货地址相关接口",tags = "收货地址管理")
@RequestMapping("/useraddr")
public class UserAddrController {

    @Autowired
    private UserAddrService userAddrService;

    @GetMapping("/list")
    @ApiImplicitParam(dataType = "int",name = "userId", value = "用户ID",required = true)
    public ResultVO listAddr(Integer userId){
        System.out.println("收货地址：userId：" + userId);
        ResultVO resultVO = userAddrService.listAddrsByUid(userId);
        return resultVO;
    }



    @PostMapping(value = "/xinzengdizhi")
    @ApiOperation("新增地址")
    @ApiImplicitParam(dataType = "UserAddrVO",name = "userAddrVO",value = "用户ID",required = true)
    public ResultVO insertaddr(@RequestBody UserAddrVO userAddrVO) {
        System.out.println("新增地址：userAddrVO" + userAddrVO);
        ResultVO resultVO = userAddrService.insertByAid(userAddrVO);
        return resultVO;


    }
    @PostMapping("/shanchudizhi")
    @ApiOperation("删除地址")
    @ApiImplicitParam(dataType = "UserAddrVO",name = "userAddrVO",value = "用户ID",required = true)
    public ResultVO deleteaddr(@RequestBody AdrrId adrrId) {
        System.out.println("adrrId:" + adrrId);
        return userAddrService.deleteByAid(adrrId);

       /* if (delete) {
            ResultVO resultVO = new ResultVO(ResStatus.ADDR_CODE_DELETE_SUCCESS, ResStatus.ADDR_MSG_DELETE_SUCCESS);
            return resultVO;
        }else {
            ResultVO resultVO = new ResultVO(ResStatus.ADDR_CODE_DELETE_FAILED, ResStatus.ADDR_MSG_DELETE_FAILED);
            return resultVO;
        }*/
    }
    @PostMapping("/xiugaidizhi")
    @ApiOperation("修改地址")
    @ApiImplicitParam(dataType = "UserAddrVO",name = "userAddrVO",value = "用户ID",required = true)
    public ResultVO updateaddr(@RequestBody UserAddrVO userAddrVO) {
        System.out.println("修改地址： UserAddrVO" + userAddrVO);
        ResultVO resultVO = userAddrService.updateByAid(userAddrVO);
        return resultVO;

    }


    @GetMapping("/getAll")
    @ApiOperation("获取所有")
    public ResultVO getAlladdr(Integer userId){

        ResultVO resultVO = userAddrService.getAlladdr(userId);
        return resultVO;
    }



}
